package com.yunji.cabinet.service.impl;

import com.yunji.base.cache.BaseCache;
import com.yunji.cabinet.cache.CabinetCache;
import com.yunji.cabinet.dao.ICabinetDao;
import com.yunji.cabinet.dao.ITakeDeliveryDao;
import com.yunji.cabinet.domain.ContainerDO;
import com.yunji.cabinet.domain.TakeDeliveryDO;
import com.yunji.cabinet.params.RecordParam;
import com.yunji.cabinet.service.ITakeDeliveryService;
import com.yunji.cabinet.vo.TakeDeliveryVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TakeDeliveryServiceImpl implements ITakeDeliveryService {

    @Resource
    ITakeDeliveryDao takeDeliveryDao;

    @Resource
    ICabinetDao cabinetDao;

    @Override
    public void create(TakeDeliveryDO takeDeliveryDO) {
        takeDeliveryDao.save(takeDeliveryDO);
    }

    @Override
    public List<TakeDeliveryVO> searchPageList(RecordParam param) {
        List<TakeDeliveryVO> voList = takeDeliveryDao.searchPageList(param);
        voList.stream().forEach(vo -> {
            vo.setSiteName(BaseCache.getSiteName(vo.getSiteId()));
            vo.setAgentName(BaseCache.getAgentName(vo.getAgentId()));
            ContainerDO containerDO = cabinetDao.getByImei(vo.getChipImei());
            if (containerDO != null) {
                vo.setContainerName(CabinetCache.getCabinetName(vo.getChipImei()));
            }
        });
        return voList;
    }
}
